﻿import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate, inf
import pandas as pd
x = np.linspace(0.01, 5, 15)


def to_be_integrate(t, _x):     # 被积函数
    return t * np.exp(-(t**2)) * np.exp(-2*t*_x)


plt.figure(figsize=(7, 8), dpi=98)
e2 = np.exp(-(x*x))
sqrtPi = np.sqrt(np.pi)

A = np.exp(-(x**2)) / ((np.pi**0.5) * x)
b = (1+2*x)

B1 = [(1 - 2 * integrate.quad(to_be_integrate, 0, inf, args=(i, ))[0]) for i in x]
B2 = (e2 / (sqrtPi*x))
erfc = B1*B2

f3 = e2/(x*sqrtPi)

C1 = (2-3*np.exp(-(1+2*x))-2*x*np.exp(-(1+2*x))) / ((1+2*x)**2)
propose = e2*(1-C1)/(sqrtPi*x)

f9 = np.exp(-(x*x))

D1 = (e2/50) + ((np.exp(-(x*x/2))) / (2*(x+1)))
f10 = 2*np.sqrt(2)*D1

E1 = 2*(x*x+2)*np.exp(-(x*x/2))
f11 = E1 / (sqrtPi*x*(x*x+3))

line_width = 2
# plt.semilogy(x, erfc, '-0', lw=line_width, label='erfc (x)')
# plt.semilogy(x, propose, '-o', lw=line_width, label='the proposed upper bound')
# plt.semilogy(x, f3, '-v', lw=line_width, label='the upper bound in (3)')
# plt.semilogy(x, f9, '-3', lw=line_width, label='the upper bound in (9)')
# plt.semilogy(x, f10, '-s', lw=line_width, label='the upper bound in (10)')
# plt.semilogy(x, f11, '-4', lw=line_width, label='the upper bound in (11)')

print(x)
print(erfc)
print(propose)
print(f3)
print(f9)
print(f10)
print(f11)


plt.plot(x, propose/erfc, "-o", lw=line_width, label='the proposed upper bound')
plt.plot(x, f3/erfc, "-2", lw=line_width, label='the upper bound in (3)')

d = {'x': x,
     'erfc(x)': erfc,
     'the proposed upper bound': propose,
     'the upper bound in (3)': f3,
     'the upper bound in (9)': f9,
    'the upper bound in (10)': f10,
    'the upper bound in (11)': f11
     }

data = pd.DataFrame(d)
data.to_csv("全部数据.csv")


# plt.ylim(np.log10(1/(10**10)), 0)
plt.ylim(0.5, 5)
plt.legend()
plt.show()